package drg_group.beijing_2022.MDC;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;

import drg_group.beijing_2022.Base;
import drg_group.beijing_2022.MedicalRecord;
import drg_group.beijing_2022.ADRG.*;

public class MDCM{
    public static String group(MedicalRecord record){
        String[] mdc_zd={"D29.000","N50.804","Q54.800","S37.910","Q55.502","N48.800x009","N50.800x041","D40.704","I86.200","B37.402+N51.2*","Q55.601","S30.208","N45.002","Q53.201","C79.820","Q55.600x009","S38.200x004","D40.001","S38.200x003","A59.000x003+N51.0*","T83.601","N50.800x001","D40.700x003","C63.900","D07.601","Q53.101","S39.900x010","A18.119+N51.8*","D29.900","N50.808","N50.900x006","Q55.600x008","Z41.200","N41.200","N50.815","Q56.100","Q55.801","N50.900x008","C60.900","R86.800","D40.701","D40.901","D17.700x034","D29.701","N43.100","C79.819","A54.204+N51.1*","D18.000x815","N49.900","N50.800x042","N48.808","Q53.100x001","N48.804","S30.203","N49.201","S39.900x007","S38.001","N48.400x008","Q85.900x032","N45.000","N48.901","N48.400x006","C63.200","S37.804","N50.800x016","N49.800","R86.900x003","N40.x01","Q56.001","N43.000","N48.301","N43.302","S30.206","D29.702","N42.300","N48.801","N50.814","N44.x00","Q55.901","N45.902","C63.000","N50.807","N48.000x003","I89.000x023","I87.120","D29.401","N49.103","Q53.202","N50.823","D07.401","C79.800x233","N47.x01","N46.x00","N48.102","N50.000","N42.000","Q55.606","N49.203","D07.500","N42.200","Q55.404","N47.x02","A54.202+N51.0*","N46.x02","N45.905","N49.001","C62.001","Q54.100","C79.818","Q55.004","D29.100","N42.901","N50.816","D07.400","Q54.901","C62.900","N48.803","D40.100x002","C63.100","N47.x03","Q55.202","N41.800","N50.806","Q53.000x002","N43.001","N50.826","Q53.901","N50.900x007","D40.900x001","N49.101","N50.813","N48.100","N43.400","N48.500","N48.807","C79.817","N50.103","I86.100","N50.811","D07.602","A18.118+N51.1*","E29.800","N45.001","N42.301","D18.108","N48.805","C62.901","C63.702","A18.100x018+N51.8*","N49.002","E29.102","Q55.501","N50.800x012","Q55.800","Q53.200x001","N48.809","E29.001","Q53.902","N50.800x023","N36.801","N50.825","D17.700x033","D07.402","N50.800x028","N48.000","N43.101","N50.101","N50.827","Q53.200","A54.203+N51.1*","N48.203","E29.000","N48.806","D40.702","N49.104","C79.815","N48.001","C63.700","Q55.401","R86.901","N48.401","N50.800x038","C79.800x231","A06.800x004+N51.2*","A18.100x020+N51.8*","A60.000x004+N51.8*","N42.802","N40.x00","N50.818","A56.103+N51.1*","E29.100x004","Q55.602","N50.824","I89.000x022","I89.000x024","S37.801","R86.500","S31.300x002","Q53.100","A56.102+N51.1*","D29.700x005","Q55.101","I86.101","N49.205","N41.300","D07.603","N48.800x005","N48.812","R86.902","C60.201","Q53.000x003","N50.809","I87.804","E29.105","N48.202","R86.903","N50.800x014","N50.812","N50.901","C63.201","N49.204","N45.903","N42.801","D40.700x002","Q56.400","Q55.900","D29.700x004","Q56.002","N48.204","N48.600","C60.100","Z31.000x004","N50.100x001","N50.900x005","E29.002","R86.600","Q55.300","N50.803","N48.101","N48.811","Q55.802","C60.901","N47.x00x001","N50.820","Q53.000","Q54.200","S38.200x005","Q85.900x047","D40.000x001","N50.102","N50.801","N46.x00x007","N44.x02","Q54.001","S31.301","R86.400","N48.201","Q54.400","C79.816","D17.600x001","I89.008","C63.801","C63.800","Q56.000","E29.104","D29.703","A18.109+N51.0*","E29.106","S39.904","S30.205","N42.101","N45.907","I89.800x010","D48.127","Q55.001","Q55.405","E89.501","N41.900x002","Q54.000","A18.110+N51.8*","S30.202","Q55.203","C62.000","Q54.300","S37.802","A60.003+N51.8*","S39.900x009","D40.700x001","S38.000","D40.101","Q55.600x007","C62.100","N45.906","Q55.200x901","Q55.605","D40.703","Q55.400x008","N50.817","C63.701","N48.400x005","N50.805","R86.100","Q55.002","N50.822","T83.401","N48.400","Q55.100x002","N43.301","N41.101","S37.811","R86.000","C60.200","Q53.900","E29.103","A18.116+N51.8*","N41.100","D29.001","R86.200","N48.300","T19.800x002","E29.100x002","Q54.900","D29.400","B26.000+N51.1*","R86.700","N50.800x025","D18.000x855","R93.802","D18.000x818","Q53.102","N50.821","S31.300x001","N44.x01","N41.000","N48.402","N48.403","N48.400x007","Q55.402","N50.903","N41.900x001","N50.800","N50.800x024","N45.901","N50.800x027","Q55.800x001","N49.102","Q55.603","N50.810","R86.300","A18.117+N51.1*","E29.100","N43.300","N50.819","D29.200","N46.x01","T83.600","Q55.201","S31.501","N48.802","Q55.403","Q55.400x006","N50.802","E29.101","N43.201","E29.000x002","C60.000","C61.x00","Q56.300","E29.900","N49.202","C79.800x228","S31.200","C60.800","N50.800x002","Q55.604","Q55.003","N45.904","D29.300","N50.902","N42.102","N45.908","N48.810","N48.813"};
        String[] dept_list={};
        if (!(true && Base.contains(mdc_zd,record.zdList[0]) && record.gender!=null && record.gender.equals("1"))){
            return "";
        }
        
        Base.groupMessages.putMessage(record.Index,"符合MDCM入组条件，匹配规则：主诊断匹配、男性");
        String result;

        result=MA1.group(record);
        if (result.length()>0){
            return result;
        }

        result=MB1.group(record);
        if (result.length()>0){
            return result;
        }

        result=MC1.group(record);
        if (result.length()>0){
            return result;
        }

        result=MD1.group(record);
        if (result.length()>0){
            return result;
        }

        result=MJ1.group(record);
        if (result.length()>0){
            return result;
        }

        if (false && record.ssList!=null && record.ssList.length>0  && Base.intersect(Base.SS_VALID,record.ssList)){
            Base.groupMessages.putMessage(record.Index,"符合MQY入组条件，存在有效手术操作："+String.join(",",Base.Intersect(record.ssList,Base.SS_VALID)));
            return "MQY";
        }

        result=MR1.group(record);
        if (result.length()>0){
            return result;
        }

        result=MS1.group(record);
        if (result.length()>0){
            return result;
        }

        result=MZ1.group(record);
        if (result.length()>0){
            return result;
        }

        Base.groupMessages.putMessage(record.Index,"不符合MDCM的ADRG入组条件");
        return "";
    }
}

